package projekt;

//import java.net.URL;
//import java.applet.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.io.FileInputStream;
import java.net.URL;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;

public class Sound {

    public void playwav(String file) {
        try {
            URL playSound = getClass().getResource("Audio/" + file);
            final AudioClip player = Applet.newAudioClip(playSound);
            new Thread() {
                public void run() {
                    player.play();
                    try {
                        Thread.sleep(4000); // all sounds are less than 300 ms long
                    } catch (InterruptedException ex) { /* i know, i know... */ }
                    player.stop();
                }
            }.start();
        } catch (Exception e) {
        }
    }

    public void playmid(String file) {
        try {
            Sequencer sequencer = MidiSystem.getSequencer();
            if (sequencer == null) {
                throw new MidiUnavailableException();
            }
            sequencer.open();
            FileInputStream is = new FileInputStream("src/projekt/Audio/" + file);
            Sequence seq = MidiSystem.getSequence(is);
            sequencer.setSequence(seq);
            sequencer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
// Sound player = new Sound();
// player.play("coins.wav"); används för att spela upp filen
// Sound player = new Sound();
// player.play("sm3-clear"); för at spela upp filen

